package ngat.oss;

import ngat.message.OSS.*;
import ngat.util.logging.*;
import ngat.phase2.*; 
import ngat.instrument.*;
import ngat.phase2.nonpersist.*;

import java.text.*;
import java.util.*;
import java.io.*;

/**
 * Action: Sent by USR to register a new user with the OSS.
 * @author S.N.Fraser
 */
public class REGISTER_TOOLImpl extends TransactionImpl {

    /** Host address of the machine it is being installed on.*/
    String clientAddress;
    
    /** Name of user who is registering this installation.*/
    String clientName;
    
    /** User's installation directory.*/
    String installDir;
 
    /** Create a REGISTER_TOOLImpl for the supplied request.*/
    public REGISTER_TOOLImpl(REGISTER_TOOL request) {
	super(request);
	this.clientAddress = request.getClientAddress();
	this.clientName    = request.getClientName();
	this.installDir    = request.getInstallDir();
    }
    
    /**
     * Registers the user specified as the installer.
     * The return code is just current time in millis as no 2 Transactions are
     * ever allowed to run simultaneously so it is guaranteed unique.
     * @return unique registration id.
     */
    public TRANSACTION_DONE exec() { 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 'T' HH:mm:ss");
	myLog = LogManager.getLogger("PEST");

	long time = System.currentTimeMillis();
	
	myLog.log(1, CLASS, id, "exec", 
		   "PEST: Installation requested"+
		  "\n\tOn host:   "+clientAddress+
		  "\n\tBy user:   "+clientName+
		  "\n\tInstalDir: "+installDir+
		  "\n\tAt:        "+sdf.format(new Date(time))+
		  "\n\tReg ID:    "+Long.toHexString(time).toUpperCase());

	System.err.println("PEST: Installed on Host: ["+clientAddress+
			   "] by user: ("+clientName+
			   ") in: "+installDir+
			   " at: "+sdf.format(new Date(time))+
			   " reg: ["+Long.toHexString(time).toUpperCase()+"]");
		
	REGISTER_TOOL_DONE done = new REGISTER_TOOL_DONE(id);
	done.setRegistrationCode(time);
	done.setSuccessful(true);
	return done;
	
    }
   
}

/** $Log: REGISTER_TOOLImpl.java,v $
/** Revision 1.1  2006/11/27 08:45:00  snf
/** Initial revision
/**
/** Revision 1.1  2001/11/21 17:50:35  snf
/** Initial revision
/**
/** Revision 1.1  2001/02/23 18:51:14  snf
/** Initial revision
/** */
